package Queue;


public class MyListQueue {
    private Node rear;
    private Node front;
    private int size = 0;

    public class Node {
        private Object obj;
        private Node next;

        public Node() {
        }

        public Node(Object obj, Node next) {
            this.obj = obj;
            this.next = next;
        }
    }

    //1.入列
    public void push(Object obj) {
        Node newNode = new Node(obj, null);
        if (rear == null) {
            rear = newNode;
            front = newNode;
        } else {
            newNode.next = front;
            front= newNode;
            }
        size++;
    }

    //2.出队peek
    public Object peek(){
        if (size <= 0){
            return null;
        }
        Object obj =rear.obj;
        return obj;
    }
    //3.出列pull
    public Object pull(){
        if (size <= 0) {
            return null;
        }

        return null;
    }
    //    10.打印出在集合中的有效元素
    public String toString(){
        StringBuilder sb = new StringBuilder("[");
        Node node = front;
        while(node.next != null){
            node = node.next;
            sb.append(node.obj + ",");
        }
        sb.deleteCharAt(sb.length()-1);
        sb.append("]");
        return sb.toString();
    }
    //找到index位置之前的一个节点

}
